package service.impl;

import dao.supplier.SupplierMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pojo.Supplier;
import service.SupplierService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 崔书健
 * @date 2024/7/22
 */
@Transactional
@Service("supplierService")
public class SupplierServiceImpl implements SupplierService {



//    @Autowired
    @Resource
    private SupplierMapper supplierMapper;

    public void setSupplierMapper(SupplierMapper supplierMapper) {
        this.supplierMapper = supplierMapper;
    }

    @Override
    public List<Supplier> getList(String supName) {
        return supplierMapper.getList(supName);
    }

    @Override
    public boolean add(Supplier supplier) {
        boolean result = false;
        try {
            if (supplierMapper.add(supplier) == 1){
                result = true;
                // 测试事务回滚时，打开注释
//                throw new RuntimeException();
            }
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
        return result;
    }

    @Override
    public boolean upd(Supplier supplier) {
        boolean result = false;
        try {
            if (supplierMapper.upd(supplier) == 1){
                result = true;
                // 测试事务回滚时，打开注释
//                throw new RuntimeException();
            }
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
        return result;
    }

    @Override
    public boolean del(int id) {
        boolean result = false;
        try {
            if (supplierMapper.del(id) == 1){
                result = true;
                // 测试事务回滚时，打开注释
//                throw new RuntimeException();
            }
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
        return result;
    }
}
